package com.health.sportplay.controller;

import com.alibaba.fastjson.JSON;
import com.health.sportplay.bean.User;
import com.health.sportplay.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class LoginController {
  @Autowired
  private UserDao userDao;

  @RequestMapping("/login")
  public String login(@RequestBody User user){
    String falg = "error";
    User us = userDao.getUserByMessage(user.getUsername(), user.getPassword());
    HashMap<String, Object> res = new HashMap<>();  //map封装
    if (us != null){
      falg = "ok";
    }
    res.put("flag",falg);
    res.put("user",user);
//    System.out.println(res);
    String s = JSON.toJSONString(res);
//    System.out.println(s);
    return s;
  }
}
